package com.overlord.im.commons.mq.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.ImmediateAcknowledgeAmqpException;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.retry.MessageRecoverer;
import org.springframework.amqp.rabbit.support.ListenerExecutionFailedException;

/**
 * @ClassName RetryFailAckRecover
 * @Author wuwei
 * @Description NONE
 * @Date 2020/4/16 10:30
 **/
@Slf4j
public class RetryFailAckRecover implements MessageRecoverer {

    @Override
    public void recover(Message message, Throwable cause) {
        log.info("messageId:{}已到达最大重试次数,将抛弃执行", message.getMessageProperties().getMessageId());
        throw new ListenerExecutionFailedException("Retry Policy Exhausted",
            new ImmediateAcknowledgeAmqpException(cause), message);
    }

}
